/*
 * CSV.h
 *
 *  Created on: Jan 15, 2011
 *      Author: LyonsDesktop
 */

#ifndef CSV_H_
#define CSV_H_
#include <string>
#include <vector>
#include <set>

#include <iostream>
#include <fstream>
#include <sstream>

namespace CLEVER
{
	namespace Datasets
	{
//		class DoubleArrayStorage;
		namespace Formats
		{
			//! Read a CSV document from file.
			class CSVReader
			{
			public:
				CSVReader(const char* filename);
				CSVReader(const char* filename, double* realData, double* metaData, unsigned int rExamples, int rNumRealAtt, int rNumMetaAtt, std::set<double>& wClusterID);
				//CSVReader(const char* filename, DoubleArrayStorage& wRealStorage, DoubleArrayStorage& wMetaStorage);
				//! The number of lines in this CSV document.
				int NumLines();

				//! Retrieves the indexed line from the CSV document.
				std::vector<std::string> GetLine(int line_index);

			private:
				std::vector<std::string> lines;
			};

			//! Writes a CSV document to file.
			class CSVWriter
			{
			public:
				CSVWriter(const char* filename);
				~CSVWriter();

				//! Appends the value to the current line in the document.
				void WriteValue(double v);

				//! Ends the current line and starts a new line.
				void Newline();
				void Close();

			private:
				bool hasline;
				std::ofstream* outfile;
			};
		}
	}
}

#endif /* CSV_H_ */
